base.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import abc
  2. from pip._vendor.six import add_metaclass
  3. from pip._internal.utils.typing import MYPY_CHECK_RUNNING
  4. if MYPY_CHECK_RUNNING:
  5. from typing import Optional
  6. from pip._vendor.pkg_resources import Distribution
  7. from pip._internal.req import InstallRequirement
  8. from pip._internal.index.package_finder import PackageFinder
  9. @add_metaclass(abc.ABCMeta)
  10. class AbstractDistribution(object):
  11. """A base class for handling installable artifacts.
  12. The requirements for anything installable are as follows:
  13. - we must be able to determine the requirement name
  14. (or we can't correctly handle the non-upgrade case).
  15. - for packages with setup requirements, we must also be able
  16. to determine their requirements without installing additional
  17. packages (for the same reason as run-time dependencies)
  18. - we must be able to create a Distribution object exposing the
  19. above metadata.
  20. """
  21. def __init__(self, req):
  22. # type: (InstallRequirement) -> None
  23. super(AbstractDistribution, self).__init__()
  24. self.req = req
  25. @abc.abstractmethod
  26. def get_pkg_resources_distribution(self):
  27. # type: () -> Optional[Distribution]
  28. raise NotImplementedError()
  29. @abc.abstractmethod
  30. def prepare_distribution_metadata(self, finder, build_isolation):
  31. # type: (PackageFinder, bool) -> None
  32. raise NotImplementedError()